const fs     = require('fs');
const path   = require('path');
const Router = require('koa-router');

const router = new Router();

fs.readdirSync(__dirname, {withFileTypes:true})
    .forEach((file)=>{
        if( file.name === 'index.js' || !file.isFile() || path.extname(file.name) !== '.js' ) { return; }
        const sr = require(`./${file.name}`);
        router.use('/'+path.basename(file.name, '.js'), sr.routes(), sr.allowedMethods());
        console.log(path.basename(file.name, '.js'));
    });


module.exports = router;
